package com.victor.bookretail.common;

import lombok.Data;

@Data
public class AppResponse<T> {
    private int code;
    private String message;
    private T data;

    private AppResponse() {
    }

    public static <T> AppResponse<T> error(ResultCode resultCode) {
        AppResponse<T> response = new AppResponse<>();
        response.code = resultCode.getCode();
        response.message = resultCode.getMessage();
        return response;
    }

    public static <T> AppResponse<T> success(T data) {
        AppResponse<T> response = new AppResponse<>();
        response.code = ResultCode.SUCCESS.getCode();
        response.message = ResultCode.SUCCESS.getMessage();
        response.data = data;
        return response;
    }
}
